﻿using Meiam.System.Interfaces;
using Meiam.System.Interfaces.IService;
using Meiam.System.Model.Entity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Meiam.System.Model.Dto;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SqlSugar;
using System.Text;
using System.Data;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Meiam.System.Model;
using Microsoft.Extensions.Logging;


namespace Meiam.System.Hostd.Controllers.Gokin
{
    /// <summary>
    /// 库存托备注
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BXBarcodeRemarkController : ControllerBase
    {
        private readonly ILogger<BXBarcodeRemarkRequestDto> _logger;
        public readonly IWMSTokenCheckService _WMSTokenCheckService;
        public readonly string con;
        public readonly string con2;


        public BXBarcodeRemarkController(ILogger<BXBarcodeRemarkRequestDto> logger,IWMSTokenCheckService wmsTokenCheckService, IConfiguration _configuration)
        {
            _logger = logger;
            _WMSTokenCheckService = wmsTokenCheckService;
             con= _configuration.GetConnectionString("DDM_DbConnection_ZH");
            con2 = _configuration.GetConnectionString("WMSDbConnection_ZH");

        }

        /// <summary>
        /// 库存托备注
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult PostBXBarcodeRemark([FromBody] BXBarcodeRemarkRequestDto strparm)
        {
            string  strMsg = "";
            object log = "";
            log = strparm;
            StringBuilder strSql = new StringBuilder();
            List<string> strSqlList = new List<string>();
            BXBarcodeRemarkRequestDto result = new BXBarcodeRemarkRequestDto();
            BXBarcodeRemarkResponseDto re = new BXBarcodeRemarkResponseDto();
            string ddate = strparm.ddate;

            //框架查询方法
            //var data = _WMSTokenCheckService.GetTokenCheckData(supplier_code);

            try
            {
                if (ddate.Trim() != "")
                {

                }


                strSql = new StringBuilder();
                strSql.Append(@"select *  from iwms_sql_temp where 1=1 and  pzid='SYS0001'");               
                DataTable dt_sql = DB.Query(strSql.ToString(), con);
                if (dt_sql.Rows.Count <= 0)
                {
                    strMsg = "无数据，请检查清楚再调用接口";
                }
                else
                {
                    string temp_sql = dt_sql.Rows[0]["temp_info"].ToString();

                    DataTable dt_remark = DB.Query(temp_sql, con2);


                    re.data = DB.TableToListModel<BXBarcodeRemarkResponseData>(dt_remark);
                }





            }
            catch (Exception ex)
            {
                strMsg = ex.ToString();
            }

         


            if (strMsg=="")
            {
                re.status = "成功";
                re.code = "0";
            }
            else
            {
                re.status = "失败";
                re.code = "500";
                re.message = strMsg;
            }


            return new JsonResult(re);
        }

      
    }
}
